﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edit_user.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.User.edit_user" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);
        var get_user = new TblUserController().FetchAll().Where(x => x.UserId == id).Single();
        var get_city = (from p in new TblCityController().FetchAll() select p).ToList();
        if (get_user.Address != null)
            get_city = (from p in new TblCityController().FetchAll().Where(x => x.Id == get_user.Address) select p).ToList();
    %>
    <div class="edit-modal w3-modal-content w3-card-8 w3-animate-bottom" style="width: 45%">
        <header class="w3-padding w3-center w3-teal">
            <span class="w3-large">CHỈNH SỬA NGƯỜI DÙNG</span>
        </header>
        <div id="edit_student_form" class="w3-row w3-padding w3-text-black">
            <div class="w3-row w3-padding-bottom">
                <span class="w3-text-teal">Những thông tin có đánh dấu <i class="fa fa-star w3-text-red w3-small"></i>&nbsp;là bắt buộc nhập.</span><br />
                <span id="edit_error_msg" class="w3-text-red"></span>
            </div>
            <div id="edit_user_id" class="w3-hide"><%=id %></div>
            <div id="edit_check_number" class="w3-hide">0</div>
            <div id="edit_check_username" class="w3-hide">0</div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Mã học viên</span>
                <input class="w3-col l4" id="edit_txt_studentnumber" value="<%=get_user.NumberStudy %>" maxlength="10" name="fullname" type="text" placeholder="Nhập mã học viên" autofocus="autofocus" required="required" />
                <span class="w3-col l4 w3-text-red w3-padding-top" id="edit_error_msg_number" style="display: none">&nbsp;Mã học viên đã tồn tại</span>
            </div>
            <div class="w3-row w3-padding-bottom" style="display: none" id="edit_exits_username"></div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Tên đăng nhập</span>
                <input class="w3-col l4" id="edit_txt_user_username" maxlength="15" name="username" type="text" disabled="disabled" value="<%=get_user.UserName %>" placeholder="Nhập tên đăng nhập" autofocus="autofocus" required="required" />
                <span class="w3-col l4 w3-text-red w3-padding-top" id="edit_error_msg_username" style="display: none">&nbsp;Tên đăng nhập đã tồn tại</span>
            </div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Họ tên</span>
                <input class="w3-col l8" id="edit_txt_fullname" value="<%=get_user.FullName %>" maxlength="40" name="fullname" type="text" placeholder="Nhập họ tên đầy đủ" autofocus="autofocus" required="required" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Ngày sinh</span>
                <div class="w3-col l2 w3-padding-right">
                    <select id="edit-reg-day">
                        <%for (int i = 1; i <= 31; i++)
                          {
                              if (i == DateTime.Parse(get_user.BirthDay.ToString()).Day)
                              {%>
                        <option selected="selected" value="<%=i %>"><%=i %></option>
                        <%}
                              else
                              { %>
                        <option value="<%=i %>"><%=i %></option>
                        <%} %>
                        <%} %>
                    </select>
                </div>
                <div class="w3-col l2 w3-padding-right">
                    <select id="edit-reg-month">
                        <%for (int i = 1; i <= 12; i++)
                          {
                              if (i == DateTime.Parse(get_user.BirthDay.ToString()).Month)
                              {%>
                        <option selected="selected" value="<%=i %>"><%=i %></option>
                        <%}
                              else
                              { %>
                        <option value="<%=i %>"><%=i %></option>
                        <%} %>
                        <%} %>
                    </select>
                </div>
                <div class="w3-col l3 w3-padding-right">
                    <select id="edit-reg-year">
                        <%
                            int get_year = DateTime.Now.Year - 5;
                            for (int i = get_year; i >= get_year - 40; i--)
                            {
                                if (i == DateTime.Parse(get_user.BirthDay.ToString()).Year)
                                {%>
                        <option selected="selected" value="<%=i %>"><%=i %></option>
                        <%}
                                else
                                { %>
                        <option value="<%=i %>"><%=i %></option>
                        <%} %>
                        <%} %>
                    </select>
                </div>
            </div>
            <div class="w3-row w3-padding-bottom">
                <div class="w3-third w3-text-teal w3-padding-top"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Giới tính</div>
                <div class="radio w3-third">
                    <%if (get_user.Sex == true)
                      {%>
                    <input type="radio" name="sex" value="1" checked="checked" id="edit-reg-male" /><label for="edit-reg-male">Nam</label>&nbsp;
                                    <input type="radio" name="sex" value="0" id="edit-reg-female" /><label for="edit-reg-female">Nữ</label>
                    <%}
                      else
                      { %>
                    <input type="radio" name="sex" value="1" id="edit-reg-male" /><label for="edit-reg-male">Nam</label>&nbsp;
                                    <input type="radio" name="sex" checked="checked" value="0" id="edit-reg-female" /><label for="edit-reg-female">Nữ</label>
                    <%} %>
                </div>
            </div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Email</span>
                <input class="w3-col l8" id="edit_txt_user_email" value="<%=get_user.Email %>" maxlength="40" name="email" type="email" placeholder="Nhập email" autofocus="autofocus" required="required" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Số điện thoại</span>
                <input class="w3-col l8" id="edit_txt_user_phone" value="<%=get_user.Phone %>" maxlength="12" name="phone" type="text" placeholder="Nhập số điện thoại" autofocus="autofocus" required="required" />
            </div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Quê quán</span>
                <div class="w3-third w3-padding-right">
                    <select id="edit_ddl_province">
                        <%if (get_user.Address != null)
                          { %>
                        <%foreach (TblProvince province in (from p in new TblProvinceController().FetchAll() orderby p.ProvinceName ascending select p))
                          {
                              if (province.Id == get_city[0].ProvinceId)
                              {%>
                        <option selected="selected" value="<%=province.Id%>"><%=province.ProvinceName%></option>
                        <%}
                              else
                              { %>
                        <option value="<%=province.Id%>"><%=province.ProvinceName%></option>
                        <%} %>
                        <%}
                          }
                          else
                          { %>
                        <option value="0" selected="selected">Tỉnh</option>
                        <%foreach (TblProvince province in (from p in new TblProvinceController().FetchAll() orderby p.ProvinceName ascending select p))
                          { %>
                            <option value="<%=province.Id %>"><%=province.ProvinceName %></option>
                        <%} %>
                        <%} %>
                    </select>
                </div>
                <div class="w3-third">
                    <select id="edit_ddl_city">
                        <%
                            if(get_user.Address!=null)
                            {
                            foreach (TblCity city in new TblCityController().FetchAll().Where(x => x.ProvinceId == get_city[0].ProvinceId))
                          {
                              if (city.Id == get_user.Address)
                              {
                        %>
                        <option selected="selected" value="<%=city.Id %>"><%=city.CityName %></option>
                        <%
                              }
                              else
                              {
                        %>
                        <option value="<%=city.Id %>"><%=city.CityName %></option>
                        <%
                              }
                          } }%>
                    </select>
                </div>
            </div>
            <div class="w3-row w3-padding-bottom">
                <span class="w3-col l4 w3-text-teal"><i class="fa fa-star w3-text-red w3-padding-right w3-small"></i>&nbsp;Địa chỉ</span>
                <input class="w3-col l8" id="edit_txt_address" value="<%=get_user.AddressMail %>" maxlength="100" name="fullname" type="text" placeholder="Địa chỉ thường trú" autofocus="autofocus" required="required" />
            </div>
            <div class="w3-row">
                <div id="edit_user" class="w3-half"><a href="javascript:;" class="w3-btn w3-teal" style="width: 100%"><i class="fa fa-save"></i>&nbsp;Lưu</a></div>
                <div class="w3-half"><a href="javascript:;" class="w3-btn w3-red" style="width: 100%" onclick="document.getElementById('edit_user_modal').style.display='none'">&times;&nbsp;Huỷ</a></div>
            </div>
        </div>
    </div>
</body>
</html>
